<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../common/meta.jsp"%>
<%@ include file="../common/taglibs.jsp"%>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/myself/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/easyui/themes/icon.css" />
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type="text/javascript"
	src='<%=request.getContextPath()%>/dwr/interface/baseVerifyService.js'></script>
<style>
.btn {
	BORDER-RIGHT: 0px;
	BORDER-TOP: 0px;
	BACKGROUND: url(<%=request.getContextPath()%>/images/bg_rectbtn.png) -2px -2px repeat-x;
	OVERFLOW: hidden;
	BORDER: solid 1px #83858C;
}
</style>
<script type="text/javascript">
	function addSubMenu() {
		var bform = document.getElementById("ctMenuForm");
		bform.action = "menuEdit.action?operate=insertSub";
		bform.target = "_self";
		bform.submit();
	}
	function deleteMenu(menuId) {
		baseVerifyService.isMenuRefByRole(menuId, {
			callback : function(data) {
				showVerify(data, menuId);
			}
		});
	}
	function showVerify(data, menuId) {
		if (data != null && data != "") {
			parent.$.messager.alert("消息","此菜单或者其子菜单已经被角色" + data + "关联，不允许删除！","info");
			return false;
		} else if (confirm("确认删除此菜单？")) {
			$("#ctMenuForm").form("submit",{
				url: "delete.action?menuId=" + menuId,		
				success: function(data) {
					parent.$.messager.progress('close');
					parent.$.messager.alert("消息",'删除成功!','info');
					var node = parent.$("#menuTree").tree("getSelected");
					var parentNode = parent.$("#menuTree").tree('getParent',node.target);
					parent.$("#menuTree").tree('reload',parentNode.target);
					parent.$("#menuTree").tree('select',parentNode.target);
				}
			});
		}
	}
	function saveMenu() {
		parent.$.messager.progress();
		$("#ctMenuForm").form("submit",{
			url: "menuSave.action?operate=${operate}",			
			onSubmit: function() {
				var menuNameObj = this['menuName'];
				if (menuNameObj.value == "") {
					parent.$.messager.alert("消息","请输入菜单名称！","info");
					parent.$.messager.progress('close');
					menuNameObj.focus();
					return false;
				}
			},
			success: function(data) {
				parent.$.messager.progress('close');
				parent.$.messager.alert('消息','保存成功!','info');
				if('${operate}' == 'insertSub') {
					var node = parent.$("#menuTree").tree("getSelected");
					parent.$("#menuTree").tree('reload',node.target);
				} else if('${operate}' == 'editView') {
					var node = parent.$("#menuTree").tree("getSelected");
					var parentNode = parent.$("#menuTree").tree('getParent',node.target);
					parent.$("#menuTree").tree('reload',parentNode.target);
				}
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
	<form id="ctMenuForm" method="post">
		<div data-options="region:'north', border:false" id="msgDiv">
		</div>
		<div data-options="region:'center', border:false">
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'center', border:false"
					style="border: 1px solid #ccc;padding: 5px;">
						<input type="hidden" id="menuId" name="menu.menuId" value="${menu.menuId}" />
						<input type="hidden" id="parentId" name="menu.parentId" value="${menu.parentId}" />
						<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
							<tr>
								<td colspan="2" height="30px">
									<s:if test="#request.operate eq 'editView'">
										<input type="button" value="创建子菜单" class="btn" onclick="addSubMenu()"/>&nbsp;
                    					<input type="button" value="删除此菜单" class="btn" onclick="deleteMenu('${menu.menuId}')"/>
									</s:if>
									<s:else>创建菜单</s:else>
								</td>
							</tr>
							<tr>
								<td nowrap="nowrap" width="150px">菜单名称<font color="#FF0000">*</font></td>
								<td><input type="text" id="menuName" name="menu.menuName"
									value="${menu.menuName}" style="WIDTH: 250px" /></td>
							</tr>
							<tr>
								<td nowrap="nowrap" width="150px">菜单路径</td>
								<td><textarea name="menu.menuFullPath" rows="3" cols="45">${menu.menuFullPath}</textarea>
								</td>
							</tr>
							<tr>
								<td nowrap="nowrap" width="150px">菜单链接</td>
								<td><textarea name="menu.menuAction" rows="3" cols="45">${menu.menuAction}</textarea>
								</td>
							</tr>
						</table>
						<br />
						<table border="0" align="center" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><input type="button" value="保存" class="btn"
									onclick="saveMenu()" /></td>
							</tr>
						</table>
				</div>
			</div>
		</div>
	</form>
	</div>
</body>
</html>